package swing.samples.java2sdotcom.progessMonitor.copyexample;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar;

public class ProgressBarPanel extends JPanel implements CopyListener {  
    private JProgressBar bar;  
    private JLabel label;  
      
    public ProgressBarPanel() {  
        bar = new JProgressBar(1, 100);  
        bar.setStringPainted(true);  
        bar.setValue(0);  
          
        label = new JLabel("拷贝进度：");  
          
        this.add(label);  
        this.add(bar);  
    }  
  
    public void addEvent(CopyEvent e) { //在计算或者获取进度的拷贝文件进度值  
        // TODO Auto-generated method stub  
        /*if (e.getValue() == 100) { 
            bar.setValue(100); 
        } 
        bar.setValue(e.getValue());*/  
        if ((e.getValue() + 1) == 100) {  
            bar.setValue(100);  
        }  
        bar.setValue(e.getValue() + 1); //设置进度条的百分比  
    }  
}  